package com.csxy.six.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csxy.six.entity.UserAnnouncement;
import com.csxy.six.mapper.UserAnnouncementMapper;
import com.csxy.six.service.UserAnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class UserAnnouncementServiceImpl extends ServiceImpl<UserAnnouncementMapper, UserAnnouncement> implements UserAnnouncementService {
    @Autowired
    private UserAnnouncementMapper userAnnouncementMapper;

    //批量绑定用户与公告
    @Override
    public boolean batchBindUsers(Integer announceId, List<Integer> userIds) {
        List<UserAnnouncement> list = userIds.stream()
                .map(userId -> {
                    UserAnnouncement ua = new UserAnnouncement();
                    ua.setAnnounceId(announceId);
                    ua.setUserId(userId);
                    return ua;
                })
                .collect(Collectors.toList());

        return userAnnouncementMapper.batchInsert(list) > 0;
    }
}
